<template>
  <!--工作汇报 我的日报 -->
  <el-container>
    <el-header class="header-tabs">
      <el-tabs v-model="activeName" type="card" @tab-click="changeType">
        <el-tab-pane label="日报" name="1"></el-tab-pane>
        <el-tab-pane label="周报" name="2"></el-tab-pane>
        <el-tab-pane label="月报" name="3"></el-tab-pane>
      </el-tabs>
    </el-header>
    <el-header>
      <div class="left-panel">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="table_add()"
        ></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-date-picker
            v-model="searchValue.time"
            type="month"
            placeholder="请选择"
            style="width: 100%"
            value-format="YYYY-MM"
          />
          <!-- <el-input
            v-model="searchValue.search"
            placeholder="日程内容"
            clearable
          ></el-input> -->
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        :params="params"
        row-key="id"
        stripe
        @row-dblclick="handleRowDblclick"
      >
        <!-- <el-table-column label="ID" prop="id" width="50"></el-table-column> -->
        <el-table-column label="日期" width="200">
          <template #default="scope">
            <span>{{ getDayOfWeek(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="工作内容"
          prop="summary"
          min-width="200"
        ></el-table-column>
        <el-table-column
          label="工作计划"
          prop="workPlan"
          min-width="200"
        ></el-table-column>
        <el-table-column
          label="待处理问题"
          prop="pendingIssues"
          min-width="200"
        >
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="150">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                >查看</el-button
              >
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show_month(scope.row, scope.$index)"
                >查看汇报情况</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSaveSuccess"
    @closed="dialog.save = false"
    :userList="userList"
  ></save-dialog>
  <calendar-dialog
    v-if="calendarDialog.save"
    ref="calendarDialog"
    @closed="calendarDialog.save = false"
  >
  </calendar-dialog>
  <!--每月日报是否提交查询-->
  <detail-dialog v-if="dialog.detail" ref="detailDialog"></detail-dialog>
</template>

<script>
import detailDialog from "./components/detail"
import saveDialog from "./components/save"
import calendarDialog from './components/calendarDialog'
export default {
  name: "myDaily",
  components: {
    detailDialog,
    saveDialog,
    calendarDialog
  },
  data () {
    return {
      activeName: "1",
      dialog: {
        save: false,
        detail: false,
      },
      calendarDialog: {
        save: false,
        detail: false,
      },
      apiObj: this.$API.daily.getDailyList,
      params: { type: 1 },
      searchValue: {
        search: null,
        time: this.dateFormat(),
      },
      userList: []
    }
  },
  beforeMount () {
    let userId = this.$route.query.id
    if (userId) {
      this.params.adminId = userId
    }
  },
  mounted () {

  },
  methods: {
    getDayOfWeek (time) {
      const days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
      const date = new Date(time)
      const nowTime = time.slice(0, 10) + " " + days[date.getDay()]
      return nowTime
    },
    // 时间格式转化
    dateFormat () {
      let date = new Date()
      let year = date.getFullYear()
      // 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
      let month =
        date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
      let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
      let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
      let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
      let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
      // 拼接
      // return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
      return year + "-" + month
    },

    // 选择类型
    changeType (e) {
      this.params.type = e.props.name
      this.$refs.table.refresh()
    },
    //添加
    table_add () {
      this.dialog.save = true
      this.$nextTick(() => {
        this.$refs.saveDialog.open("add", this.params.type)
      })
    },
    //编辑
    table_edit (row) {
      this.dialog.save = true
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(row)
      })
    },
    //查看
    table_show (row) {
      this.$router.push({
        path: "/home/myDaily/dailyDetail",
        query: {
          id: row.id,
        },
      })
    },
    table_show_month (row) {
      this.calendarDialog.save = true
      this.$nextTick(() => {
        this.$refs.calendarDialog.open("add", row)
      })
    },
    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },

    //本地更新数据
    handleSaveSuccess (data) {
      this.params.type = data.type
      this.activeName = "" + data.type
      this.$refs.table.refresh()
    },
    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    },
  },
};
</script>

<style></style>
